{include file="public/adminhead"}

<div class="container-fluid">

  <div class="row">
    <div class="card">
      <div class="card-body">

        <form class="form-horizontal" action="#" method="post" enctype="multipart/form-data" onsubmit="return false;">


          {if $res}
          <input type="hidden" name="id" value="{$res.id}">
          {/if}

          <div class="form-group">
            <label class="col-xs-12" >名称</label>
            <div class="col-xs-12">
              <input class="form-control" type="text" {if $res}value="{$res.name}"{/if} name="name" placeholder="..">
            </div>
          </div>

          {if $res}
          {:uploader('img',$res['img'])}
          {else/}
          {:uploader('img')}
          {/if}

          <div class="form-group">
            <label class="col-xs-12" >链接地址</label>
            <div class="col-xs-12">
              <input class="form-control" type="text" {if $res}value="{$res.url}"{/if} name="url" placeholder="..">
            </div>
          </div>

          <div class="form-group">
            <label class="col-xs-12" for="example-select">广告位</label>
            <div class="col-xs-12">
              <select class="form-control" id="example-select" name="board_id" size="1">
                <option value="0">请选择</option>
                {foreach $list as $v}
                selected="selected"
                <option value="{$v.id}" {if $res and $res.board_id == $v.id}selected="selected"{/if}>{$v.name}</option>
                {/foreach}
              </select>
            </div>
          </div>

          <div class="form-group">
            <label class="col-xs-12">类型</label>
            <div class="col-xs-12">
              <div class="radio">
                <label>
                  <input type="radio" name="type" value="1"
                         {if $res}
                         {if $res.type='image'}checked="checked"{/if}
                         {else/}
                  checked="checked"
                  {/if}

                  >
                  图片
                </label>
              </div>
              <div class="radio">
                <label >
                  <input type="radio" name="type" value="0" {if $res}{if $res.type=='code'}checked="checked"{/if}{/if} >
                  代码
                </label>
              </div>
            </div>
          </div>

          <div class="form-group">
            <label class="col-xs-12" >说明</label>
            <div class="col-xs-12">
              <textarea class="form-control" name="content" rows="6" placeholder="内容..">{if $res}{$res.content}{/if} </textarea>
            </div>
          </div>


          <div class="form-group">
            <label class="col-xs-12">是否启用</label>
            <div class="col-xs-12">
              <div class="radio">
                <label>
                  <input type="radio" name="status" value="1"
                         {if $res}
                         {if $res.status==1}checked="checked"{/if}
                          {else/}
                          checked="checked"
                          {/if}

                  >
                  是
                </label>
              </div>
              <div class="radio">
                <label >
                  <input type="radio" name="status" value="0" {if $res}{if $res.status==0}checked="checked"{/if}{/if} >
                  否
                </label>
              </div>
            </div>
          </div>

          <div class="form-group">
            <div class="col-xs-12">
              <button class="btn btn-primary" type="button" onclick="sub()">提交</button>
            </div>
          </div>
        </form>

      </div>
    </div>
  </div>

</div>

{include file="public/afooter"}

<script>
function sub() {
    var formdata = $("form").serialize();
    var url = "{:url('AdminAdvert/edit')}";
    $.post(url,formdata,function (e) {
      if(e.code == 200){
          success("成功");
          var index = parent.layer.getFrameIndex(window.name);
          setTimeout(function(){parent.layer.close(index)}, 2000);
          window.parent.location.reload();
      }else {
          error(e.msg);
      }
    })
}
</script>